package com.activitycode.activity.find.searchlimit;

import java.util.ArrayList;
import java.util.List;

import com.activitycode.activity.find.FindSearchActivity;
import com.activitycode.adapter.OtherServiceAdapter;
import com.activitycode.adapter.SearchOtherApapter;
import com.duostec.zhuyue.pets.R;

import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

public class SearchOtherLimitActicity extends Activity{
	private TextView title;
	private ImageButton titleBtn;
	private Button submitBtn;
	private ListView chooseListView;
	private List<OtherChooseEntity> clist = new ArrayList<OtherChooseEntity>();
	private TextView cTextView;
	public SearchOtherApapter adapter;
	private int position1;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_choose_limit);
		initView();
		initData();
		choosed(2);
	}

	private void initView() {
		// TODO Auto-generated method stub
		//cTextView =(CheckedTextView) this.findViewById(R.id.ctextview);
		
//		cTextView = (CheckedTextView) LayoutInflater.from(this).inflate(
//				R.layout.adapter_chooselimit, null);
//		cTextView.setChecked(false);
		title = (TextView) this.findViewById(R.id.title_evalueate1_info_name);
		title.setVisibility(View.GONE);
		titleBtn = (ImageButton) this.findViewById(R.id.title_evalueate1_info_back);
		submitBtn = (Button) this.findViewById(R.id.title_evaluate1_submit);
		chooseListView = (ListView) this.findViewById(R.id.listView);
		chooseListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
		
		chooseListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				// TODO Auto-generated method stub
				choosed(position);
				
			}
		});
		
		titleBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		submitBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				submit1();
			}
		});
	}

	private void initData() {
		// TODO Auto-generated method stub
		OtherChooseEntity item = new OtherChooseEntity(this.getResources().getString(R.string.yes),false);
		clist.add(item);
		OtherChooseEntity item1 = new OtherChooseEntity(this.getResources().getString(R.string.no),false);
		clist.add(item1);
		OtherChooseEntity item2 = new OtherChooseEntity(this.getResources().getString(R.string.no_limit),false);
		clist.add(item2);
		
		adapter = new SearchOtherApapter(clist,this);
		chooseListView.setAdapter(adapter);
						
	}
	private void choosed(int position){
		for(int i = 0 ;i < clist.size(); i++){
			if(i!=position){
			clist.get(i).setChecked(false);
			}else {
				clist.get(i).setChecked(true);
			}
		}
		position1 = position;
		adapter.notifyDataSetChanged();
		
	}
	private void submit1(){
//		int position = chooseListView .getCheckedItemPosition();
		
		String limitString = clist.get(position1).getName();
		Intent intent = new Intent(SearchOtherLimitActicity.this,FindSearchActivity.class);
		intent.putExtra("limitStrings", limitString);
		setResult(RESULT_OK, intent);
		finish();
	}

}
